// Copyright 2008 Senary
// See credits.txt for details.

// This file is part of Omega VII.

// Omega VII is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Omega VII is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Omega VII.  If not, see <http://www.gnu.org/licenses/>.

#include "Stardust.h"
#include "MediaManager.h"
#include "Vector.h"

BMAP* Stardust::_starBmap = 0;

Stardust::Stardust()
{
	_starBmap = MediaManager::getInstance()->getImage("stardust.pcx");
	createEffect();
}

Stardust::~Stardust(void)
{
}

void Stardust::createParticle(PARTICLE* particle) 
{
	double x = ((double)rand() / RAND_MAX - 0.5) * UNIVERSE_SIZE.x + UNIVERSE_CENTER.x;
	double y = ((double)rand() / RAND_MAX - 0.5) * UNIVERSE_SIZE.y + UNIVERSE_CENTER.y;
	double z = ((double)rand() / RAND_MAX - 0.5) * UNIVERSE_SIZE.z + UNIVERSE_CENTER.z;

	particle->x = _VAR(x);
	particle->y = _VAR(y);
	particle->z = _VAR(z);
	particle->bmap = _starBmap;
	particle->size = _VAR(STAR_SIZE);
	particle->flags |= BRIGHT|TRANSLUCENT;
	particle->alpha = _VAR(80);
	particle->event = (EVENT)liveForever;
}

void Stardust::liveForever(PARTICLE* particle) 
{
		particle->lifespan = 1; //don't die...	
}

void Stardust::createEffect() 
{
	VECTOR universeCenter;
	UNIVERSE_CENTER.toGamestudio(&universeCenter);

	effect((EVENT)createParticle, 
			_VAR(N_STARS),
			&universeCenter, 
			NULL);
}